﻿#nullable enable

using System;

using Acl.Data.Mappings;

namespace Acl.Excel;

/// <summary>
/// Excel 查询
/// </summary>
public sealed class ExcelQueryOptions
{
    /// <summary>
    ///
    /// </summary>
    public string ExcelFile { get; set; } = default!;

    /// <summary>
    ///
    /// </summary>
    public string? SheetName { get; set; }

    /// <summary>
    ///
    /// </summary>
    public uint? RowSize { get; set; }

    /// <summary>
    ///
    /// </summary>
    public uint? ColumnSize { get; set; }

    /// <summary>
    ///
    /// </summary>
    public uint StartRowNumber { get; set; } = 1;

    /// <summary>
    ///
    /// </summary>
    public uint StartColumnNumber { get; set; } = 1;

    /// <summary>
    ///
    /// </summary>
    public bool HasHeader { get; set; } = true;

    /// <summary>
    ///
    /// </summary>
    public ColumnMappingBuilder? MappingBuilder { get; set; }

    /// <summary>
    ///
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="handler"></param>
    /// <returns></returns>
    public void SetColumnNameMapping<T>(Action<IColumnNameMappingBuilder<T>>? handler)
    {
        if(handler != null)
        {
            var builder = ColumnMappingBuilder.CreateColumnNameMappingBuilder<T>();

            handler(builder);
            MappingBuilder = builder as ColumnMappingBuilder;
        }
        else
        {
            MappingBuilder = default;
        }

     
    }

    /// <summary>
    ///
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="handler"></param>
    /// <returns></returns>
    public void CreateColumnIndexMapping<T>(Action<IColumnIndexMappingBuilder<T>>? handler)
    {
       if(handler != null)
        {
            var builder = ColumnMappingBuilder.CreateColumnIndexMappingBuilder<T>();

            handler(builder);
            MappingBuilder = builder as ColumnMappingBuilder;
        }
        else
        {
            MappingBuilder = default;
        }
    }
}